import {
  deleteOne,
  loadMovieCategory,
  saveOne,
  updateOne,
} from '@/services/ant-design-pro/FlimCategory';

export default {
  namespace: 'FilmCategory',
  state: {
    list: [],
    current: {},
    showEdit: false,
    isEdit: false,
  },
  effects: {
    /**
     *  获取数据列表
     * */
    *loadData({payload}:any, { call, put }: any) {
      const res = yield call(loadMovieCategory);
      yield put({
        type: 'save',
        payload: {
          list: res,
          showEdit: false,
          isEdit: false,
        },
      });
    },
    /**
     *新增
     */
    *insert({ payload }: any, { call, put }: any) {
      yield call(saveOne, payload);
      yield put({
        type: 'loadData',
        payload: {},
      });
    },

    *update({ payload }: any, { call, put }: any) {
      yield call(updateOne, payload.id, payload.data);
      yield put({
        type: 'loadData',
        payload: {},
      });
    },

    *delete({ payload }: any, { call, put }: any) {
      yield call(deleteOne, payload.id);
      yield put({
        type: 'loadData',
        payload: {},
      });
    },
  },
  reducers: {
    save(state: any, { payload }: any) {
      return { ...state, ...payload };
    },
  },
};
